package com.imddy.tweb.task.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class HelloScheduler {

	public static void main(String[] args) throws SchedulerException {
		// 根据HelloJob,创建JobDetail实例
		JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
				.withIdentity("hellojob", "group1")
				.usingJobData("jobmessage", "This is jobmessage")
				.usingJobData("jobFloatValue", 3.1415926F)
				.build();

		// 创建Trigger实例
		Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity("hellotrigger", "group1")
				.usingJobData("trimessage", "This is trimessage")
				.usingJobData("tridoubleValue", 200.23245D)
				.startNow().
				withSchedule(
						SimpleScheduleBuilder.simpleSchedule()
						.withIntervalInSeconds(2)
						.repeatForever()
						)
				.build();

		// 创建Scheduler实例
		SchedulerFactory schedulerFactory = new StdSchedulerFactory();
		Scheduler scheduler = schedulerFactory.getScheduler();
		scheduler.start();
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println("Current Time is: " + simpleDateFormat.format(date));
		scheduler.scheduleJob(jobDetail, trigger);
		
		

	}

}
